/**
 * 制作者：九哥
 * 注册公司数据对接
 * 时间：2019-03-20
 * */


/**
 * 引入缓存设置文件 cache.js
 * */
document.write("<script type='text/javascript' src='/h5/js/cache.js'></script>");


//var app_access = 'qSoiKwpWVge4TkaryH6MKvOdceGt7ZMaF20g8H0cnXI';


/**
 * ---------------------------------------------
 * 公司信息
 * ---------------------------------------------
 * */

/**
 * 公司信息，获取
 * */
function getComInfo() {
   /// return ;

    var userInfo = cacheGet('userInfo'); //获取用户信息
    var comInfo = cacheGet('comInfo'); //获取企业资料
    if (userInfo == null || userInfo.token == 'undefined') {
        getErrMsg('没有登录！');
        return;
    }
    var formData = {
        app_access: app_access//,
       /* token: userInfo.token,
        type: userInfo.type,
        cate: userInfo.cate*/
    };
    //获取缓存处理
    if (comInfo && comInfo.ageRange != ',') {
       // catchHtml();
    }
    //更新缓存
    $.ajax({
        type: 'post',
        url: getDomain() + 'show',
        data: formData,
        success: function (res) {
            //console.log(res); return
            if (res.code != 0) {
                getOutTypeList(''); //业务类型
                return;
            }
            var sexHtml = '';
            $('#realname')[0].value = res.data.legal_name;
            //性别
            var sex = res.data.legal_sex;
          /*  sexHtml += '<option value ="0"';
            if (sex == 0) {
                sexHtml += ' selected';
            }
            sexHtml += '>请选择性别</option>';
            sexHtml += '<option value ="1"';
            if (sex == 1) {
                sexHtml += ' selected';
            }
            sexHtml += '>男</option>';
            sexHtml += '<option value ="2"';
            if (sex == 2) {
                sexHtml += ' selected';
            }
            sexHtml += '>女</option>';
            $('#sex').html(sexHtml);
            */
          $('#sex').val(sex);
            $('#facType').val(res.data.facType);
            $('#mobile')[0].value = res.data.legal_mobile;
            $('#idcard')[0].value = res.data.legal_idcard;
            var images, imgSfzzm, imgSfzfm, imgSfzsc;
            images = res.data.legal_idcard_imgs.split("|");
            if (images[0] != '') {
                imgSfzzm = '<img src="' + images[0] + '" width="100%"/>';
                $('#sfzzmFile').html(imgSfzzm).show();
            } else {
                $('#sfzzmFile').hide();
            }
            if (images[1] != '') {
                imgSfzfm = '<img src="' + images[1] + '" width="100%"/>';
                $('#sfzfmFile').html(imgSfzfm).show();
            } else {
                $('#sfzfmFile').hide();
            }
            if (images[2] != '') {
                imgSfzsc = '<img src="' + images[2] + '" width="100%"/>';
                $('#sfzscFile').html(imgSfzsc).show();
            } else {
                $('#sfzscFile').hide();
            }
            $('#sfzzm')[0].value = images[0];
            $('#sfzfm')[0].value = images[1];
            $('#sfzsc')[0].value = images[2];
            $('#comName')[0].value = res.data.com_name;

            $('#position')[0].value = res.data.position;

            $('#comTel')[0].value = res.data.com_tel;
            $('#comFax')[0].value = res.data.com_fax;
            $('#comAddress')[0].value = res.data.com_address;
            //$('#comCity')[0].value = res.data.com_city;
            $('#comCity')[0].value = res.data.comCity;
            $('#cusLike')[0].value = res.data.cus_like;
            $('#quality')[0].value = res.data.quality;
            $('#pact')[0].value = res.data.pact;
            if (res.data.param2 && res.data.param2 != '') {
                $('#scale')[0].value = res.data.param2.scale;
                $('#totalSale')[0].value = res.data.param2.totalSale;
                $('#yearSale')[0].value = res.data.param2.yearSale;
                $('#truck')[0].value = res.data.param2.truck;
                $('#brand')[0].value = res.data.param2.brand;
            }
            $('#ageStart')[0].value = res.data.ageStart;
            $('#ageEnd')[0].value = res.data.ageEnd;
            $('#detail')[0].value = res.data.detail;
            //业务类型
            getOutTypeList(res.data.outType);
            changeInput(); // 判断星号状态
            sfzFileVal(); // 身份证星号判断
        },
        error: function () {
            console.log('操作失败！');
            return;
        }
    });
}

// 星号状态改变
function changeStatus($this) {
    if ($this.val() != '') {
        $this.prev().css({
            'color': '#569f25'
        })
    } else {
        $this.prev().css({
            'color': 'red'
        })
    }
    // 性别判断
    var sexType = $('.bossInfoSex').children('option:selected').val()
    if (sexType == 1 || sexType == 2) {
        $('.bossInfoSex').prev().css({'color': '#569f25'})
    } else {
        $('.bossInfoSex').prev().css({'color': 'red'})
    }
    catchInput() // 输入时设置缓存
}

function sfzFileVal() {
    $('.sfzFileVal').each(function () {
        if ($(this).val() != '') {
            $(this).parent().children('.bossFileText').children('span').css({'color': '#569f25'})
        } else {
            $(this).parent().children('.bossFileText').children('span').css({'color': '#red'})
        }
    })
    catchInput() // 输入时设置缓存
}

function changeInput() {
    var ageArray = []
    $('.changeStatus').each(function () {
        if ($(this).val() != '') {
            $(this).prev().css({
                'color': '#569f25'
            })
        } else {
            $(this).prev().css({
                'color': '#red'
            })
        }
    })

    // 性别判断
    var sexType = $('.bossInfoSex').children('option:selected').val()
    if (sexType == 1 || sexType == 2) {
        $('.bossInfoSex').prev().css({'color': '#569f25'})
    } else {
        $('.bossInfoSex').prev().css({'color': 'red'})
    }

    /*
    setTimeout(function () {
        businessItem()

    }, 2600)*/

    $('.businessAgePanel .businessAge').each(function () {
        if ($(this).children().val() == '') {
            ageArray.push(0)
        }
    })
    if (ageArray.length == 0) {
        $('.businessAgePanel').prev().children('span').css({
            'color': '#569f25'
        })
    } else {
        $('.businessAgePanel').prev().children('span').css({
            'color': '#red'
        })
    }

    if ($('.factoryIntroDiv').children().val() != '') {
        $('.factoryIntroDiv').prev().children('span').css({
            'color': '#569f25'
        })
    } else {
        $('.factoryIntroDiv').prev().children('span').css({
            'color': '#red'
        })
    }
}

function businessVal($this) {
    if ($this.val() != '') {
        $this.parent().prev().children('span').css({
            'color': '#569f25'
        })
    } else {
        $this.parent().prev().children('span').css({
            'color': 'red'
        })
    }
    catchInput() // 输入时设置缓存
}

function businessAge($this) {
    var businessArray = []
    $('.businessAgeValue').each(function () {
        if ($(this).val() != '') {
            businessArray.push(0)
        }
    })
    if (businessArray.length == 2) {
        $('.businessAgePanel').prev().children('span').css({
            'color': '#569f25'
        })
    } else {
        $('.businessAgePanel').prev().children('span').css({
            'color': 'red'
        })
    }
    catchInput() // 输入时设置缓存
}


function businessItem() {
    //业务类型
    var outTypeArray = []
    $('.businessItemDiv span').each(function () {
        if ($(this).children().children().prop('checked')) {
            outTypeArray.push($(this).children().children().attr('data-id'));
        }
    })

    if (outTypeArray.length != 0) {
        $('.businessItemDiv').prev().children('span').css({
            'color': '#569f25'
        })
    } else {
        $('.businessItemDiv').prev().children('span').css({
            'color': 'red'
        })
    }
    catchInput() // 输入时设置缓存
}

$('.businessItemDiv').click(function () {
    businessItem()
})

function changeNotStatus() { // 非必填设置缓存
    catchInput() // 输入时设置缓存

}


// 输入时设置缓存
function catchInput() {
    var userInfo = cacheGet('userInfo'); //获取用户信息
    var comInfo =null;// cacheGet('comInfo'); //获取企业资料

    var facType;
    if (userInfo == 'undefined' || userInfo.token == 'undefined') {
        getErrMsg('没有登录！');
        return;
    }
    if (comInfo == null || comInfo.ageRange == undefined) {
        facType = 0;
    } else {
        facType = comInfo.facType;
    }
    var realname = $('#realname').val();
    var sex = $('#sex').val();
    var mobile = $('#mobile').val();
    var idcard = $('#idcard').val();
    var sfzzm = $('#sfzzm').val();
    var sfzfm = $('#sfzfm').val();
    var sfzsc = $('#sfzsc').val();
    var comName = $('#comName').val();
    var comTel = $('#comTel').val();
    var comFax = $('#comFax').val();
    var comAddress = $('#comAddress').val();
    var comCity = $('#comCity').val();
    var cusLike = $('#cusLike').val();
    var quality = $('#quality').val();
    var pact = $('#pact').val();
    var scale = $('#scale').val();
    var totalSale = $('#totalSale').val();
    var yearSale = $('#yearSale').val();
    var truck = $('#truck').val();
    var brand = $('#brand').val();
    //业务类型
    var i, resOutType, outTypes = new Array(), outTypeStr = '', ageRange;
    $('.businessItemDiv span').each(function () {
        if ($(this).children().children().prop('checked')) {
            outTypes.push($(this).children().children().attr('data-id'));
        }
    })
    outTypeStr = outTypes.join('||');
    //console.log(outTypes,outTypeStr);
    var ageStart = $('#ageStart').val();
    var ageEnd = $('#ageEnd').val();
    var detail = $('#detail').val();
    ageRange = ageStart + ',' + ageEnd;
    var param2 = {
        scale: scale,
        totalSale: totalSale,
        yearSale: yearSale,
        truck: truck,
        brand: brand
    };
    var comInfoNew = {
        facType: facType,
        realname: realname,
        sex: sex,
        mobile: mobile,
        idcard: idcard,
        sfzzm: sfzzm,
        sfzfm: sfzfm,
        sfzsc: sfzsc,
        comName: comName,
        comTel: comTel,
        comFax: comFax,
        comAddress: comAddress,
        comCity: comCity,
        cusLike: cusLike,
        quality: quality,
        pact: pact,
        param: '',
        param2: param2,
        outTypeStr: outTypeStr,
        ageRange: ageRange,
        detail: detail
    };
    cacheSet('comInfo', comInfoNew); //缓存企业资料

    var comInfo = cacheGet('comInfo'); //获取企业资料
    console.log(comInfo);
    MC.View.pic.loadData();
}

// 通过缓存设置页面
function catchHtml() {
    return;
    var comInfo = cacheGet('comInfo'); //获取企业资料
    console.log(comInfo, '^^^^')

    $('#realname').val(comInfo.realname) // 姓名

    var sexHtml                          // 性别
    sexHtml += '<option value ="0"';
    if (comInfo.sex == 0) {
        sexHtml += ' selected';
    }
    sexHtml += '>请选择性别</option>';
    sexHtml += '<option value ="1"';
    if (comInfo.sex == 1) {
        sexHtml += ' selected';
    }
    sexHtml += '>男</option>';
    sexHtml += '<option value ="2"';
    if (comInfo.sex == 2) {
        sexHtml += ' selected';
    }
    sexHtml += '>女</option>';
    $('#sex').html(sexHtml);

    $('#mobile').val(comInfo.mobile) // 手机号
    $('#idcard').val(comInfo.idcard) // 身份证号
   // $('#facType').val(comInfo.facType);

    if (comInfo.sfzzm != '') {           // 身份证图片
        $('#sfzzmFile').html('<img src="' + comInfo.sfzzm + '" width="100%"/>').show();
    }
    if (comInfo.sfzfm != '') {
        $('#sfzfmFile').html('<img src="' + comInfo.sfzfm + '" width="100%"/>').show();
    }
    if (comInfo.sfzsc != '') {
        $('#sfzscFile').html('<img src="' + comInfo.sfzsc + '" width="100%"/>').show();
    }
    $('#sfzzm').val(comInfo.sfzzm)
    $('#sfzfm').val(comInfo.sfzfm)
    $('#sfzsc').val(comInfo.sfzsc)

    $('#comName').val(comInfo.comName)
    $('#comTel').val(comInfo.comTel)
    $('#comFax').val(comInfo.comFax)
    $('#comAddress').val(comInfo.comAddress)
    $('#comCity').val(comInfo.comCity)
    $('#cusLike').val(comInfo.cusLike)
    $('#quality').val(comInfo.quality)
    $('#pact').val(comInfo.pact)
    if (comInfo.param2 && comInfo.param2 != '') {
        $('#scale').val(comInfo.param2.scale)
        $('#totalSale').val(comInfo.param2.totalSale)
        $('#yearSale').val(comInfo.param2.yearSale)
        $('#truck').val(comInfo.param2.truck)
        $('#brand').val(comInfo.param2.brand)
    }
    if (comInfo.ageRange) {


        var ageArray = comInfo.ageRange.split(',');

        $('#ageStart').val(ageArray[0]);

        $('#ageEnd').val(ageArray[1]);

    }

    $('#detail').val(comInfo.detail);
    //业务类型
    getOutTypeList(comInfo.outTypeStr);
    // 身份证星号判断
    sfzFileVal()
}

/**
 * 公司信息，业务类型
 * */
function getOutTypeList(outTypeStr) {
    var userInfo = cacheGet('userInfo'); //获取用户信息
    if (userInfo == null || userInfo.token == 'undefined') {
        getErrMsg('没有登录！');
        return;
    }
    var data = {
        app_access: app_access,
        token: userInfo.token,
        type: userInfo.type,
        cate: userInfo.cate
    };
    $.ajax({
        type: 'post',
        url: getDomain() + 'outtype',
        data: data,
        success: function (res) {
            if (res.code != 0) {

                return;
            }
            var i, i2, i3, h = '', h2 = '', outTypes, outTypeArray = [];
            if (outTypeStr != 0) {
                outTypes = outTypeStr.split('||');
            } else {
                outTypes = '';
            }
            for (i = 0; i < res.data.length; i++) {
                h += '<span class="businessItem">';
                h += '<label class="businessValue">';
                h += '<input type="checkbox" name="businessType" class="businessCheck" onclick="setOutTypeRadio(' + res.data[i].id + ')" data-id=' + res.data[i].id + '';
                for (i2 = 0; i2 < outTypes.length; i2++) {
                    if (outTypes[i2] == res.data[i].id) {
                        h += ' checked';
                    }
                }
                h += '>';
                h += res.data[i].name;
                h += '</label>';
                h += '</span>';

            }
            $('#outType').html(h);
        },
        error: function () {
            console.log('操作失败！');
            return;
        }
    });
}

/**
 * 公司信息，业务类型设置
 * */
function setOutTypeRadio(v) {
    var type = $('#outType' + v).val();
    var outTypeMin = $('#outTypeMin').val();
    var outTypeMax = $('#outTypeMax').val();
    var i, resType, types = new Array();
    // if (type==0) {
    //     $('#outType'+v)[0].value = v;
    // } else {
    //     $('#outType'+v)[0].value = 0;
    // }
}

/**
 * 公司信息，身份证正面
 * */
function setFile(v) {
    var userInfo = cacheGet('userInfo'); //获取用户信息
    //var comInfo = cacheGet('comInfo'); //获取企业资料
    //var facType;
    if (userInfo == null || userInfo.token == 'undefined') {
        getErrMsg('没有登录！');
        return;
    }
    //if (comInfo=='undefined') {
    //    facType = 0;
    //} else {
    //    facType = comInfo.facType;
    //}
    $('form').attr('action', getDomain() + 'upload');
    $('.param').html(getFormParam(userInfo));
    $('#submit-' + v).show().css({
        'background': '#569f25',
        'color': '#fff'
    }).parent().prev().children('span').css({
        'color': '#569f25'
    })
}

$('.bossFileUp').on('click', function () { // 点击上传后清空公司信息本地缓存
    cacheSet('comInfo', ''); //缓存企业资料
})

/**
 * 公司信息，数据收集
 * */
function getFormParam(userInfo) {
    var h = '';
    h += '<input type="hidden" name="app_access" value="' + app_access + '">';
    h += '<input type="hidden" name="token" value="' + userInfo.token + '">';
    h += '<input type="hidden" name="type" value="' + userInfo.type + '">';
    h += '<input type="hidden" name="cate" value="' + userInfo.cate + '">';
    //h += '<input type="hidden" name="facType" value="'+facType+'">';
    h += '<input type="hidden" name="viewJump" value="/h5/login/company.html">';
    h += '<input type="hidden" name="realname" value="' + $("#realname").val() + '"/>';
    h += '<input type="hidden" name="sex" value="' + $("#sex").val() + '"/>';
    h += '<input type="hidden" name="mobile" value="' + $("#mobile").val() + '"/>';
    h += '<input type="hidden" name="idcard" value="' + $("#idcard").val() + '"/>';
    h += '<input type="hidden" name="sfzzm" value="' + $("#sfzzm").val() + '"/>';
    h += '<input type="hidden" name="sfzfm" value="' + $("#sfzfm").val() + '"/>';
    h += '<input type="hidden" name="sfzsc" value="' + $("#sfzsc").val() + '"/>';
    return h;
}

///**
// * 公司信息，下一步判断
// * */
//$('#companyNext').on('click',function() {
//    var h = '';
//    h += '<div onclick="setCompanyNext(1)">完成</div>';
//    h += '<div onclick="setCompanyNext(2)">下一页</div>';
//    h += '<div id="popClose" onclick="popClose()">取消</div>';
//    $('#popDetail').html(h);
//    $('#pop').show();
//});

/**
 * 公司信息，下一步判断
 * */
$('#companyNext').on('click', function () {
    var userInfo = cacheGet('userInfo'); //获取用户信息
    var comInfo = cacheGet('comInfo'); //获取企业资料
    var facType;
    if (userInfo == 'undefined' || userInfo.token == 'undefined') {
        getErrMsg('没有登录！');
        return;
    }
    if (comInfo == null) {
        facType = 0;
    } else {
        facType = comInfo.facType;
    }
    var realname = $('#realname').val();
    var sex = $('#sex').val();
    var mobile = $('#mobile').val();
    var idcard = $('#idcard').val();
    var sfzzm = $('#sfzzm').val();
    var sfzfm = $('#sfzfm').val();
    var sfzsc = $('#sfzsc').val();
    var comName = $('#comName').val();
    var comTel = $('#comTel').val();
    var comFax = $('#comFax').val();
    var comAddress = $('#comAddress').val();
    var comCity = $('#comCity').val();
    var cusLike = $('#cusLike').val();
    var quality = $('#quality').val();
    var pact = $('#pact').val();
    var scale = $('#scale').val();
    var totalSale = $('#totalSale').val();
    var yearSale = $('#yearSale').val();
    var truck = $('#truck').val();
    var brand = $('#brand').val();
    //业务类型
    var outTypeMin = $('#outTypeMin').val();
    var outTypeMax = $('#outTypeMax').val();
    var i, resOutType, outTypes = new Array(), outTypeStr = '', ageRange;
    for (i = outTypeMin; i < outTypeMax; i++) {
        resOutType = $('#outType' + i).val();
        if (resOutType != 0) {
            outTypes.push(resOutType);
        }
    }
    outTypeStr = outTypes.join('||');
    //console.log(outTypes,outTypeStr);
    var ageStart = $('#ageStart').val();
    var ageEnd = $('#ageEnd').val();
    var detail = $('#detail').val();
    //if (facType == 0) {
    //    getErrMsg('工厂类型为填选！');
    //    return;
    //}
    if (realname == '') {
        getErrMsg('法人名称未填写！');
        return;
    }
    if (sex == 0) {
        getErrMsg('法人性别未填选！');
        return;
    }
    if (mobile == '') {
        getErrMsg('法人手机号码未填写！');
        return;
    }
    if (idcard == '') {
        getErrMsg('法人身份证号码未填写！');
        return;
    }
    if (sfzzm == '') {
        getErrMsg('法人身份证正面照未上传！');
        return;
    }
    if (sfzfm == '') {
        getErrMsg('法人身份证反面照未上传！');
        return;
    }
    if (sfzsc == '') {
        getErrMsg('法人身份证手持照未上传！');
        return;
    }
    if (comName == '') {
        getErrMsg('公司名称未填写！');
        return;
    }
    if (comTel == '') {
        getErrMsg('公司座机未填写！');
        return;
    }
    if (comFax == '') {
        getErrMsg('公司传真未填写！');
        return;
    }
    if (comAddress == '') {
        getErrMsg('公司地址未填写！');
        return;
    }
    if (comCity == '') {
        getErrMsg('公司所在地未填写！');
        return;
    }
    if (scale == '') {
        getErrMsg('公司规模量未填写！');
        return;
    }
    if (totalSale == '') {
        getErrMsg('销售额未填写！');
        return;
    }
    if (yearSale == '') {
        getErrMsg('年销售额未填写！');
        return;
    }
    if (truck == '') {
        getErrMsg('送货车辆未填写！');
        return;
    }
    if (pact == '') {
        getErrMsg('合同履行率未填写！');
        return;
    }
    if (cusLike == '') {
        getErrMsg('客户满意度未填写！');
        return;
    }
    if (quality == '') {
        getErrMsg('品质合格率未填写！');
        return;
    }
    if (brand == '') {
        getErrMsg('品牌未填写！');
        return;
    }
    if (outTypeStr == '') {
        getErrMsg('业务类型未选择！');
        return;
    }
    if (ageStart == '' || ageEnd == '') {
        getErrMsg('年龄段未填写！');
        return;
    }
    ageRange = ageStart + ',' + ageEnd;
    if (detail == '') {
        getErrMsg('公司介绍未填写！');
        return;
    }
    var param2 = {
        scale: scale,
        totalSale: totalSale,
        yearSale: yearSale,
        truck: truck,
        brand: brand
    };
    //var param2 = {
    //};
    var comInfoNew = {
        facType: facType,
        realname: realname,
        sex: sex,
        mobile: mobile,
        idcard: idcard,
        sfzzm: sfzzm,
        sfzfm: sfzfm,
        sfzsc: sfzsc,
        comName: comName,
        comTel: comTel,
        comFax: comFax,
        comAddress: comAddress,
        comCity: comCity,
        cusLike: cusLike,
        quality: quality,
        pact: pact,
        param: '',
        param2: param2,
        outTypeStr: outTypeStr,
        ageRange: ageRange,
        detail: detail
    };
    var data = {
        app_access: app_access,
        token: userInfo.token,
        type: userInfo.type,
        cate: userInfo.cate,
        comInfo: comInfoNew
    };
    cacheSet('comInfo', comInfoNew); //缓存企业资料
    //console.log(data); return;
    $.ajax({
        type: 'post',
        url: getDomain() + 'modify',
        data: data,
        success: function (res) {
            //console.log(res); return;
            if (res.code != 0) {
                console.log(res);
                return;
            }
            //if (v==1) {
            //    window.location.href = '../index.html';
            //} else {
            //    window.location.href = 'comFile.html';
            //}
            setCompanyNext();
        },
        error: function () {
            console.log('操作失败！');
            return;
        }
    });
});

/**
 * 公司信息，下一步
 * */
function setCompanyNext() {
    var h = '';
    h += '<div onclick="window.location.href = \'/h5/index.html\';">完成</div>';
    h += '<div onclick="window.location.href = \'/h5/login/comFile.html\';">下一页</div>';
    h += '<div id="popClose" onclick="popClose()">取消</div>';
    $('#popDetail').html(h);
    $('#pop').show();
}

/**
 * 弹窗取消
 * */
function popClose() {
    $('#popDetail').html('');
    $('#pop').hide();
}

///**
// * 公司信息，下一步
// * */
//function setCompanyNext(v) {
//}

/**
 * ---------------------------------------------
 * 公司信息
 * ---------------------------------------------
 * */


/**
 * ---------------------------------------------
 * 公司认证
 * ---------------------------------------------
 * */

/**
 * 公司认证，获取
 * */
function geComFile(type) {
    var userInfo = cacheGet('userInfo'); //获取用户信息
    //var comInfo = cacheGet('comInfo'); //获取企业资料
    //var comFile = cacheGet('comFile'); //获取企业证书
    if (userInfo == null || userInfo.token == 'undefined') {
        getErrMsg('没有登录！');
        return;
    }
    var data = {
        app_access: app_access,
        token: userInfo.token,
        type: userInfo.type,
        cate: userInfo.cate,
        type:type
    };
    $.ajax({
        type: 'post',
        url: getDomain() + 'filelist',
        data: data,
        success: function (res) {
            //console.log(res); return;
            if (res.code != 0) {
                console.log(res);
                return;
            }
            console.log(res);
            for(var key in res.data.coms){
                var val=res.data.coms[key];
                $('#'+key).val(val);
            }
            for(var key in res.data.legals){
                var val=res.data.legals[key];
                $('#'+key).val(val);
            }
            MC.View.pic.loadData();
        },
        error: function () {
            console.log('操作失败！');
            return;
        }
    });
}

/**
 * 公司认证，
 * 形象照、身份证、毕业证、奖状、结婚证、驾驶证、
 * 组织机构代码证、营业执照、税务登记证、租赁合同、许可证、荣誉证书、房产证、
 * */
function setFormFile(v) {
    $('form').attr('action', getDomain() + 'file-upload');
    $('.param').html(getFormFileParam());
    $('#submit-' + v).show();
}

/**
 * 公司认证，公司证书收集
 * */
function getFormFileParam() {
    var userInfo = cacheGet('userInfo'); //获取用户信息
    var comInfo = cacheGet('comInfo'); //获取企业资料
    //var comFile = cacheGet('comFile'); //获取企业证书
    if (userInfo == null || userInfo.token == 'undefined') {
        getErrMsg('没有登录！');
        return;
    }
    if (comInfo.facType == 'undefined') {
        getErrMsg('没有选择工厂类型！');
        return;
    }
    var h = '';
    h += '<input type="hidden" name="app_access" value="' + app_access + '">';
    h += '<input type="hidden" name="token" value="' + userInfo.token + '">';
    h += '<input type="hidden" name="type" value="' + userInfo.type + '">';
    h += '<input type="hidden" name="cate" value="' + userInfo.cate + '">';
    h += '<input type="hidden" name="facType" value="' + comInfo.facType + '">';
    h += '<input type="hidden" name="viewJump" value="/h5/login/facFile.html">';
    //h += '<input type="hidden" name="xxz" value="'+$("#xxz").val()+'"/>';
    //h += '<input type="hidden" name="sfz" value="'+$("#sfz").val()+'"/>';
    //h += '<input type="hidden" name="byz" value="'+$("#byz").val()+'"/>';
    //h += '<input type="hidden" name="jz" value="'+$("#jz").val()+'"/>';
    //h += '<input type="hidden" name="jhz" value="'+$("#jhz").val()+'"/>';
    //h += '<input type="hidden" name="jsz" value="'+$("#jsz").val()+'"/>';
    //h += '<input type="hidden" name="zzjgdmz" value="'+$("#zzjgdmz").val()+'"/>';
    //h += '<input type="hidden" name="yyzz" value="'+$("#yyzz").val()+'"/>';
    //h += '<input type="hidden" name="swdjz" value="'+$("#swdjz").val()+'"/>';
    //h += '<input type="hidden" name="zlht" value="'+$("#zlht").val()+'"/>';
    //h += '<input type="hidden" name="xkz" value="'+$("#xkz").val()+'"/>';
    //h += '<input type="hidden" name="ryzs" value="'+$("#ryzs").val()+'"/>';
    //h += '<input type="hidden" name="fcz" value="'+$("#fcz").val()+'"/>';
    return h;
}

/**
 * 公司认证，下一步
 * */
$('#comFileNext').on('click', function () {
    var userInfo = cacheGet('userInfo'); //获取用户信息
    if (userInfo == null || userInfo.token == 'undefined') {
        getErrMsg('没有登录！');
        return;
    }
    //console.log(userInfo); return;
    if (userInfo.type == 2) { //无工厂
        window.location.href = 'comPro.html';
    } else {
        window.location.href = 'comFacType.html';
    }
});

/**
 * ---------------------------------------------
 * 公司认证
 * ---------------------------------------------
 * */


/**
 * ---------------------------------------------
 * 工厂类型
 * ---------------------------------------------
 * */

/**
 * 工厂类型
 * */
function getComFacTypes() {
    var i, h = '';
    var userInfo = cacheGet('userInfo'); //获取用户信息
    var comInfo = cacheGet('comInfo'); //获取企业资料
    if (userInfo == null || userInfo.token == 'undefined') {
        getErrMsg('没有登录！');
        return;
    }
    var data = {
        app_access: app_access,
        token: userInfo.token,
        type: userInfo.type,
        cate: 3 //3代表公司含工厂
    };
    $.ajax({
        type: 'post',
        url: getDomain() + 'typelist',
        data: data,
        success: function (res) {
            //console.log(res); return;
            if (res.code != 0) {
                console.log(res);
                return;
            }
            var types = res.data;
            for (i = 0; i < types.length; i++) {
                h += '<div class="factoryTypePanel">';
                h += '<div class="factoryTypeItem">';
                h += '<span class="factoryItem';
                if (comInfo.facType == types[i][1].id) {
                    h += ' facClick';
                }
                h += '" id="facType' + types[i][1].id + '"  onclick="setFacType(' + types[i][1].id + ')">' + types[i][1].name + '</span>';
                h += '</div>';
                if (types[i][0]) {
                    h += '<div class="factoryTypeItem">';
                    h += '<span class="factoryItem';
                    if (comInfo.facType == types[i][0].id) {
                        h += ' facClick';
                    }
                    h += '" id="facType' + types[i][0].id + '" onclick="setFacType(' + types[i][0].id + ')">' + types[i][0].name + '</span>';
                    h += '</div>';
                } else {
                    h += '<div class="factoryTypeItem">';
                    h += '<span class="factoryItem">&nbsp;</span>';
                    h += '</div>';
                }
                h += '</div>';
            }
            $('#facTypeList').html(h);
        },
        error: function () {
            console.log('操作失败！');
            return;
        }
    });
}

/**
 * 工厂类型选择
 * */
function setFacType(v) {
    $('.factoryItem').removeClass('facClick');
    $('#facType' + v).addClass('facClick');
    var comInfo = {
        facType: v
    };
    cacheSet('comInfo', comInfo); //设置企业资料
    getErrMsg('设置成功！');
}

/**
 * 工厂类型提交，下一页
 * */
$('#comFacTypeNext').on('click', function () {
    var userInfo = cacheGet('userInfo'); //获取用户信息
    var comInfo = cacheGet('comInfo'); //获取企业资料
    if (userInfo == null || userInfo.token == 'undefined') {
        getErrMsg('没有登录！');
        return;
    }
    if (comInfo == 'undefined' || !comInfo.facType) {
        getErrMsg('工厂类型未设置！');
        return;
    }
    cacheSet('comInfo', comInfo); //缓存企业资料
    window.location.href = 'comPro.html';
});

/**
 * ---------------------------------------------
 * 工厂类型
 * ---------------------------------------------
 * */


/**
 * ---------------------------------------------
 * 公司产品
 * ---------------------------------------------
 * */

/**
 * 产品，获取
 * */
function getProductList() {
    var userInfo = cacheGet('userInfo'); //获取用户信息
    if (userInfo == 'undefined' || userInfo.token == 'undefined') {
        getErrMsg('没有登录！');
        return;
    }
    var cate = 2; //2代表公司，3代表公司含工厂
    if (userInfo.cate == 3) {
        cate = 3;
    }
    var data = {
        app_access: app_access,
        token: userInfo.token,
        type: userInfo.type,
        cate: cate
    };
    $.ajax({
        type: 'post',
        url: getDomain() + 'product-list',
        data: data,
        success: function (res) {
            //console.log(res); return;
            if (res.code != 0) {
                console.log(res);
                return;
            }
            //console.log(res.data); return;
            var zhens = res.data.zhens, suos = res.data.suos, baos = res.data.baos;
            var i, i2, i3, h = '', h2 = '', h3 = '', param = '';
            for (i = 0; i < zhens.length; i++) {
                h += '<style>input[type="checkbox"] {width:20px;height:20px;cursor:pointer;s}</style>';
                h += '<div class="goodsPanel">';
                h += '<div class="goodsNameLast">' + zhens[i].name + '</div>';
                h += '<div class="goodsItemOneLast">';
                h += '<input type="checkbox" onclick="setZhen(1,' + zhens[i].id + ')"';
                if (zhens[i].pros[1] != 0) {
                    h += ' checked';
                }
                h += '/>';
                h += '</div>';
                h += '<div class="goodsItemTwoLast">';
                h += '<input type="checkbox" onclick="setZhen(2,' + zhens[i].id + ')"';
                if (zhens[i].pros[2] != 0) {
                    h += ' checked';
                }
                h += '/>';
                h += '</div>';
                h += '<div class="goodsItemThreeLast">';
                h += '<input type="checkbox" onclick="setZhen(3,' + zhens[i].id + ')"';
                if (zhens[i].pros[3] != 0) {
                    h += ' checked';
                }
                h += '/>';
                h += '</div>';
                h += '</div>';
                param += '<input type="hidden" id="zhen-1-' + zhens[i].id + '" value="';
                if (zhens[i].pros[1] != 0) {
                    param += 1;
                } else {
                    param += 0;
                }
                param += '"/>';
                param += '<input type="hidden" id="zhen-2-' + zhens[i].id + '" value="';
                if (zhens[i].pros[2] != 0) {
                    param += 1;
                } else {
                    param += 0;
                }
                param += '"/>';
                param += '<input type="hidden" id="zhen-3-' + zhens[i].id + '" value="';
                if (zhens[i].pros[3] != 0) {
                    param += 1;
                } else {
                    param += 0;
                }
                param += '"/>';
            }
            $('#zhenlist').html(h);
            for (i2 = 0; i2 < suos.length; i2++) {
                h2 += '<div class="goodsPanel">';
                h2 += '<div class="goodsNameLast">' + suos[i2].name + '</div>';
                h2 += '<div class="goodsItemOneLast">';
                h2 += '<input type="checkbox" onclick="setSuo(1,' + suos[i2].id + ')"';
                if (suos[i2].pros&&suos[i2].pros[1] != 0) {
                    h2 += ' checked';
                }
                h2 += '/>';
                h2 += '</div>';
                h2 += '<div class="goodsItemTwoLast">';
                h2 += '<input type="checkbox" onclick="setSuo(2,' + suos[i2].id + ')"';
                if (suos[i2].pros&&suos[i2].pros[2] != 0) {
                    h2 += ' checked';
                }
                h2 += '/>';
                h2 += '</div>';
                h2 += '<div class="goodsItemThreeLast">';
                h2 += '<input type="checkbox" onclick="setSuo(3,' + suos[i2].id + ')"';
                if (suos[i2].pros&&suos[i2].pros[3] != 0) {
                    h2 += ' checked';
                }
                h2 += '/>';
                h2 += '</div>';
                h2 += '</div>';
                param += '<input type="hidden" id="suo-1-' + suos[i2].id + '" value="';
                if (suos[i2].pros&&suos[i2].pros[1] != 0) {
                    param += 1;
                } else {
                    param += 0;
                }
                param += '"/>';
                param += '<input type="hidden" id="suo-2-' + suos[i2].id + '" value="';
                if (suos[i2].pros&&suos[i2].pros[2] != 0) {
                    param += 1;
                } else {
                    param += 0;
                }
                param += '"/>';
                param += '<input type="hidden" id="suo-3-' + suos[i2].id + '" value="';
                if (suos[i2].pros&&suos[i2].pros[3] != 0) {
                    param += 1;
                } else {
                    param += 0;
                }
                param += '"/>';
            }
            $('#suolist').html(h2);
            for (i3 = 0; i3 < baos.length; i3++) {
                h3 += '<div class="goodsPanel">';
                h3 += '<div class="goodsNameLast">' + baos[i3].name + '</div>';
                h3 += '<div class="goodsItemOneLast">';
                h3 += '<input type="checkbox" onclick="setBao(1,' + baos[i3].id + ')"';
                if (baos[i3].pros&&baos[i3].pros[1] != 0) {
                    h3 += ' checked';
                }
                h3 += '/>';
                h3 += '</div>';
                h3 += '<div class="goodsItemTwoLast">';
                h3 += '<input type="checkbox" onclick="setBao(2,' + baos[i3].id + ')"';
                if (baos[i3].pros&&baos[i3].pros[2] != 0) {
                    h3 += ' checked';
                }
                h3 += '/>';
                h3 += '</div>';
                h3 += '<div class="goodsItemThreeLast">';
                h3 += '<input type="checkbox" onclick="setBao(3,' + baos[i3].id + ')"';
                if (baos[i3].pros&&baos[i3].pros[3] != 0) {
                    h3 += ' checked';
                }
                h3 += '/>';
                h3 += '</div>';
                h3 += '</div>';
                param += '<input type="hidden" id="bao-1-' + baos[i3].id + '" value="';
                if (baos[i3].pros&&baos[i3].pros[1] != 0) {
                    param += 1;
                } else {
                    param += 0;
                }
                param += '"/>';
                param += '<input type="hidden" id="bao-2-' + baos[i3].id + '" value="';
                if (baos[i3].pros&&baos[i3].pros[2] != 0) {
                    param += 1;
                } else {
                    param += 0;
                }
                param += '"/>';
                param += '<input type="hidden" id="bao-3-' + baos[i3].id + '" value="';
                if (baos[i3].pros&&baos[i3].pros[3] != 0) {
                    param += 1;
                } else {
                    param += 0;
                }
                param += '"/>';
            }
            $('#baolist').html(h3);
            param += '<input type="hidden" id="zhenIdStr" value="' + res.data.zhenIdStr + '">';
            param += '<input type="hidden" id="suoIdStr" value="' + res.data.suoIdStr + '">';
            param += '<input type="hidden" id="baoIdStr" value="' + res.data.baoIdStr + '">';
            $('#paramSpan').html(param);
        },
        error: function () {
            console.log('操作失败！');
            return;
        }
    });
}

/**
 * 产品针织类，设置
 * */
function setZhen(type, value) {
    var zhen = $('#zhen-' + type + '-' + value).val();
    if (zhen != 0) {
        $('#zhen-' + type + '-' + value)[0].value = 0;
    } else {
        $('#zhen-' + type + '-' + value)[0].value = 1;
    }
}

/**
 * 产品梭织类，设置
 * */
function setSuo(type, value) {
    var suo = $('#suo-' + type + '-' + value).val();
    if (suo != 0) {
        $('#suo-' + type + '-' + value)[0].value = 0;
    } else {
        $('#suo-' + type + '-' + value)[0].value = 1;
    }
}

/**
 * 产品箱包类，设置
 * */
function setBao(type, value) {
    var bao = $('#bao-' + type + '-' + value).val();
    if (bao != 0) {
        $('#bao-' + type + '-' + value)[0].value = 0;
    } else {
        $('#bao-' + type + '-' + value)[0].value = 1;
    }
}

/**
 * 产品提交，设置
 * */
$('#comProNext').on('click', function () {
    var userInfo = cacheGet('userInfo'); //获取用户信息
    if (userInfo == 'undefined' || userInfo.token == 'undefined') {
        getErrMsg('没有登录！');
        return;
    }
    var zhenIdStr = $('#zhenIdStr').val();
    var zhenIds = zhenIdStr.split('-');
    var zhens = new Array();
    for (var i = 0; i < zhenIds.length; i++) {
        zhens[i] = [
            zhenIds[i],
            $('#zhen-1-' + zhenIds[i]).val(),
            $('#zhen-2-' + zhenIds[i]).val(),
            $('#zhen-3-' + zhenIds[i]).val()
        ];
    }
    var suoIdStr = $('#suoIdStr').val();
    var suoIds = suoIdStr.split('-');
    var suos = new Array();
    for (var i2 = 0; i2 < suoIds.length; i2++) {
        suos[i2] = [
            suoIds[i2],
            $('#suo-1-' + suoIds[i2]).val(),
            $('#suo-2-' + suoIds[i2]).val(),
            $('#suo-3-' + suoIds[i2]).val()
        ];
    }
    var baoIdStr = $('#baoIdStr').val();
    var baoIds = baoIdStr.split('-');
    var baos = new Array();
    for (var i3 = 0; i3 < baoIds.length; i3++) {
        baos[i3] = [
            baoIds[i3],
            $('#bao-1-' + baoIds[i3]).val(),
            $('#bao-2-' + baoIds[i3]).val(),
            $('#bao-3-' + baoIds[i3]).val()
        ];
    }
    //console.log(zhens,suos,baos); return;
    var cate = 2; //2代表公司，3代表公司含工厂
    if (userInfo.cate == 3) {
        cate = 3;
    }
    var data = {
        app_access: app_access,
        token: userInfo.token,
        type: userInfo.type,
        cate: cate,
          zhens:JSON.stringify(zhens),
            suos:JSON.stringify(suos),
            baos:JSON.stringify(baos)
    };
    $.ajax({
        type: 'post',
        url: getDomain() + 'fac-pro-set',
        data: data,
        success: function (res) {
            //console.log(res); return;
            if (res.code != 0) {
                getErrMsg(res.msg);
                return;
            }
            window.location.href = 'comStyle.html';
        },
        error: function () {
            getErrMsg('操作失败！');
            return;
        }
    });
});

/**
 * ---------------------------------------------
 * 公司产品
 * ---------------------------------------------
 * */


/**
 * ---------------------------------------------
 * 公司风格
 * ---------------------------------------------
 * */

/**
 * 风格，获取
 * */
function getStyleList() {
    var userInfo = cacheGet('userInfo'); //获取用户信息
    if (userInfo == 'undefined' || userInfo.token == 'undefined') {
        getErrMsg('没有登录！');
        return;
    }
    var data = {
        app_access: app_access,
        token: userInfo.token,
        type: userInfo.type,
        cate: userInfo.cate
    };
    $.ajax({
        type: 'post',
        url: getDomain() + 'style-list',
        data: data,
        success: function (res) {
            //console.log(res); return;
            if (res.code != 0) {
                console.log(res);
                return;
            }
            //console.log(res.data); return;
            var i, h = '', h2 = '', che = '', data = res.data.styles;
            for (i = 0; i < data.length; i++) {
                if (data[i].check != 0) {
                    che = 'checked'
                } else {
                    che = ''
                }
                h += '<div class="goodsPanel">';
                h += '<div class="goodsNameStyle">' + data[i].name + '</div>';
                h += '<div class="goodsCheckStyle">';
                h += '<input class="goodsCheckInput" data-id="' + data[i].id + '" type="checkbox" ' + che + ' onclick="setStyle(' + data[i].id + ')"';
                if (data[i].check == 1) {
                    h += ' checked';
                }
                h += ' width="20" height="20"/>';
                h += '</div>';
                h += '</div>';
                h2 += '<input type="hidden" id="style-' + data[i].id + '" value="';
                if (data[i].check != 0) {
                    h2 += 1;
                } else {
                    h2 += 0;
                }
                h2 += '"/>';
            }
            h2 += '<input type="hidden" id="styleIdStr" value="' + res.data.styleIdStr + '"/>';
            $('#stylelist').html(h);
            $('#styleSpan').html(h2);
        },
        error: function () {
            console.log('操作失败！');
            return;
        }
    });
}

/**
 * 风格，设置
 * */
function setStyle(v) {
    var style = $('#style-' + v).val();
    if (style != 0) {
        $('#style-' + v)[0].value = 0;
    } else {
        $('#style-' + v)[0].value = 1;
    }
}

/**
 * 风格，下一页
 * */
$('#comStyleNext').on('click', function () {
    var userInfo = cacheGet('userInfo'); //获取用户信息
    if (userInfo == 'undefined' || userInfo.token == 'undefined') {
        getErrMsg('没有登录！');
        return;
    }
    var styleIdStr = $('#styleIdStr').val();
    var styleIds = styleIdStr.split('-');
    var styles = new Array();
    for (var i = 0; i < styleIds.length; i++) {
        styles[i] = [styleIds[i], $('#style-' + styleIds[i]).val()];
    }
    var data = {
        app_access: app_access,
        token: userInfo.token,
        type: userInfo.type,
        cate: userInfo.cate,
        styles: styles
    };
    //console.log(styleIds,styles); return;
    $.ajax({
        type: 'post',
        url: getDomain() + 'com-style-set',
        data: data,
        success: function (res) {
            //console.log(res); return;
            if (res.code != 0) {
                getErrMsg(res.msg);
                return;
            }
            window.location.href = 'comDesign.html';
        },
        error: function () {
            getErrMsg('操作失败！');
            return;
        }
    });
});

/**
 * ---------------------------------------------
 * 公司风格
 * ---------------------------------------------
 * */


/**
 * ---------------------------------------------
 * 公司产品种类
 * ---------------------------------------------
 * */

/**
 * 种类，获取
 * */
function getProTypes() {
    var userInfo = cacheGet('userInfo'); //获取用户信息
    if (userInfo == 'undefined' || userInfo.token == 'undefined') {
        getErrMsg('没有登录！');
        return;
    }
    var data = {
        app_access: app_access,
        token: userInfo.token,
        type: userInfo.type,
        cate: userInfo.cate
    };
    $.ajax({
        type: 'post',
        url: getDomain() + 'com-pro-type-list',
        data: data,
        success: function (res) {
            //console.log(res); return;
            var h = '';
            h += '<div class="goodsPanel">';
            h += '<div class="deviceInner proType">';
            h += '<input type="text" class="regCodeCenter" id="cate" placeholder="输入" value=""/>';
            h += '</div>';
            h += '<div class="deviceInner proType">';
            h += '<input type="text" class="regCodeCenter" id="name" placeholder="输入" value=""/>';
            h += '</div>';
            h += '<div class="deviceInner proType">';
            h += '<input type="text" class="regCodeCenter" id="male" placeholder="输入" value=""/>';
            h += '</div>';
            h += '<div class="deviceInner proType">';
            h += '<input type="text" class="regCodeCenter" id="female" placeholder="输入" value=""/>';
            h += '</div>';
            h += '<div class="deviceOuter proType">';
            h += '<input type="text" class="regCodeCenter" id="child" placeholder="输入" value=""/>';
            h += '</div>';
            h += '</div>';
            if (res.code != 0) {
                $('#proTypeSpan').append(h);
                console.log(res);
                return;
            }
            //console.log(res.data); return;
            var i, h2 = '', data = res.data;
            for (i = 0; i < data.length; i++) {
                h2 += '<div class="goodsPanel">';
                h2 += '<div class="deviceInner proType">';
                h2 += '<input type="text" class="regCodeCenter" value="' + data[i].cate + '"/>';
                h2 += '</div>';
                h2 += '<div class="deviceInner proType">';
                h2 += '<input type="text" class="regCodeCenter" value="' + data[i].name + '"/>';
                h2 += '</div>';
                h2 += '<div class="deviceInner proType">';
                h2 += '<input type="text" class="regCodeCenter" value="' + data[i].male + '"/>';
                h2 += '</div>';
                h2 += '<div class="deviceInner proType">';
                h2 += '<input type="text" class="regCodeCenter" value="' + data[i].female + '"/>';
                h2 += '</div>';
                h2 += '<div class="deviceOuter proType">';
                h2 += '<input type="text" class="regCodeCenter" value="' + data[i].child + '"/>';
                h2 += '</div>';
                h2 += '</div>';
            }
            $('#proTypeSpan').html(h2);
            $('#proTypeSpan').append(h);
        },
        error: function () {
            console.log('操作失败！');
            return;
        }
    });
}

/**
 * 种类，新增
 * */
function setProTypeAdd() {
    var userInfo = cacheGet('userInfo'); //获取用户信息
    if (userInfo == 'undefined' || userInfo.token == 'undefined') {
        getErrMsg('没有登录！');
        return;
    }
    var cate = $('#cate').val();
    var name = $('#name').val();
    var male = $('#male').val();
    var female = $('#female').val();
    var child = $('#child').val();
    if (cate == '') {
        getErrMsg('类别未填写！');
        return;
    }
    if (name == '') {
        getErrMsg('产品名称未填写！');
        return;
    }
    if (male == '') {
        getErrMsg('男装未填写！');
        return;
    }
    if (female == '') {
        getErrMsg('女装未填写！');
        return;
    }
    if (child == '') {
        getErrMsg('童装未填写！');
        return;
    }
    if (!/^[0-9]*$/.test(male)) {
        getErrMsg('男装输入格式错误！');
        console.log('男装输入格式错误！');
        return
    }
    if (!/^[0-9]*$/.test(female)) {
        getErrMsg('女装输入格式错误！');
        console.log('女装输入格式错误！');
        return
    }
    if (!/^[0-9]*$/.test(child)) {
        getErrMsg('童装输入格式错误！');
        console.log('童装输入格式错误！');
        return
    }
    var proType = {
        cate: cate,
        name: name,
        male: male,
        female: female,
        child: child
    };
    var data = {
        app_access: app_access,
        token: userInfo.token,
        type: userInfo.type,
        cate: userInfo.cate,
        proType: proType
    };
    $.ajax({
        type: 'post',
        url: getDomain() + 'com-pro-type-set',
        data: data,
        success: function (res) {
            //console.log(res); return;
            if (res.code != 0) {
                console.log(res);
                return;
            }
            window.location.href = 'comProType.html';
        },
        error: function () {
            console.log('操作失败！');
            return;
        }
    });
}

///**
// * 种类，下一页
// * */
//$('#comProTypeNext').on('click',function(){
//});

/**
 * ---------------------------------------------
 * 公司产品种类
 * ---------------------------------------------
 * */


/**
 * ---------------------------------------------
 * 公司产品款式数量
 * ---------------------------------------------
 * */

/**
 * 款式，获取
 * */
function getDesignList() {
    var userInfo = cacheGet('userInfo'); //获取用户信息
    if (userInfo == 'undefined' || userInfo.token == 'undefined') {
        getErrMsg('没有登录！');
        return;
    }
    var data = {
        app_access: app_access,
        token: userInfo.token,
        type: userInfo.type,
        cate: userInfo.cate
    };
    $.ajax({
        type: 'post',
        url: getDomain() + 'com-design-list',
        data: data,
        success: function (res) {
            //console.log(res); return;
            var h = '';
            h += '<style>.deviceName{font-size:12px;}</style>';
            h += '<div class="goodsPanel">';
            h += '<div class="goodsCheckStyleLast">';
            h += '<input type="text" class="regCodeCenter" id="name"/>';
            h += '</div>';
            h += '<div class="goodsRightStyleLast">';
            h += '<input type="text" class="regCodeCenter" id="num"/>';
            h += '</div>';
            h += '</div>';
            if (res.code != 0) {
                $('#designSpan').html(h);
                console.log(res);
                return;
            }
            var data = res.data;
            var i, h2 = '';
            for (i = 0; i < data.length; i++) {
                h2 += '<div class="goodsPanel">';
                h2 += '<div class="goodsNameStyleLast">' + data[i].name + '</div>';
                h2 += '<div class="goodsRightStyleLast">';
                h2 += '<input type="text" class="regCodeCenter" id="num-' + data[i].id + '" value="' + data[i].num + '"/>';
                h2 += '</div>';
                h2 += '</div>';
            }
            $('#designSpan').html(h2);
            $('#designSpan').append(h);
        },
        error: function () {
            console.log('操作失败！');
            return;
        }
    });
}

/**
 * 款式，新增
 * */
function setDesignAdd() {
    var userInfo = cacheGet('userInfo'); //获取用户信息
    if (userInfo == 'undefined' || userInfo.token == 'undefined') {
        getErrMsg('没有登录！');
        return;
    }
    var name = $('#name').val();
    var num = $('#num').val();
    if (name == '') {
        getErrMsg('款式名称未填写！');
        return;
    }
    if (num == '') {
        getErrMsg('数量未填写！');
        return;
    }
    var design = {
        name: name,
        num: num
    };
    var data = {
        app_access: app_access,
        token: userInfo.token,
        type: userInfo.type,
        cate: userInfo.cate,
        design: design
    };
    $.ajax({
        type: 'post',
        url: getDomain() + 'com-design-set',
        data: data,
        success: function (res) {
            //console.log(res); return;
            if (res.code != 0) {
                console.log(res);
                return;
            }
            window.location.href = 'comDesign.html';
        },
        error: function () {
            console.log('操作失败！');
            return;
        }
    });
}

/**
 * ---------------------------------------------
 * 公司产品款式数量
 * ---------------------------------------------
 * */


/**
 * ---------------------------------------------
 * 公司的工厂设备
 * ---------------------------------------------
 * */

/**
 * 工厂设备，获取
 * */
function getComEquipList() {
    var userInfo = cacheGet('userInfo'); //获取用户信息
    if (userInfo == 'undefined' || userInfo.token == 'undefined') {
        getErrMsg('没有登录！');
        return;
    }
    var data = {
        app_access: app_access,
        token: userInfo.token,
        type: userInfo.type,
        cate: userInfo.cate
    };
    $.ajax({
        type: 'post',
        url: getDomain() + 'com-equip-list',
        data: data,
        success: function (res) {
            //console.log(res); return;
            if (res.code != 0) {
                console.log(res.msg);
                return;
            }
            //console.log(res.data); return;
            var equips = res.data.equips;
            var i, h = '';
            h += '<style>.deviceName{font-size:12px;}</style>';
            for (i = 0; i < equips.length; i++) {
                h += '<div class="goodsPanel">';
                h += '<div class="deviceName">' + equips[i].name + '</div>';
                h += '<div class="deviceInner">';
                h += '<input type="text" class="regCodeCenter" id="brand-' + equips[i].id + '" value="';
                if (equips[i][1]) {
                    h += equips[i][1];
                }
                h += '"/>';
                h += '</div>';
                h += '<div class="deviceInner">';
                h += '<input type="text" class="regCodeCenter" id="year-' + equips[i].id + '" value="';
                if (equips[i][2]) {
                    h += equips[i][2];
                }
                h += '"/>';
                h += '</div>';
                h += '<div class="deviceInner">';
                h += '<input type="text" class="regCodeCenter" id="num-' + equips[i].id + '" value="';
                if (equips[i][3]) {
                    h += equips[i][3];
                }
                h += '"/>';
                h += '</div>';
                h += '<div class="deviceOuter">';
                h += '<input type="checkbox" onclick="setEquipCheck(' + equips[i].id + ')"';
                if (equips[i][4] && equips[i][4] == 1) {
                    h += ' checked';
                }
                h += '/>';
                h += '</div>';
                h += '</div>';
                h += '<input type="hidden" id="equip-' + equips[i].id + '" value="';
                if (equips[i][4] && equips[i][4] == 0) {
                    h += 1;
                } else {
                    h += 0;
                }
                h += '"/>';
            }
            h += '<input type="hidden" id="equipIdStr" value="' + res.data.equipIdStr + '"/>';
            $('#equipSpan').html(h);
        },
        error: function () {
            console.log('操作失败！');
            return;
        }
    });
}

/**
 * 设备选择，设置
 * */
function setEquipCheck(v) {
    //console.log(v);
    var equip = $('#equip-' + v).val();
    if (equip != 0) {
        $('#equip-' + v)[0].value = 0;
    } else {
        $('#equip-' + v)[0].value = 1;
    }
}

/**
 * 设备提交，设置
 * */
$('#comEquipNext').on('click', function () {
    var userInfo = cacheGet('userInfo'); //获取用户信息
    if (userInfo == 'undefined' || userInfo.token == 'undefined') {
        getErrMsg('没有登录！');
        return;
    }
    var equipIdStr = $('#equipIdStr').val();
    var equipIds = equipIdStr.split('-');
    var equips = new Array();
    for (var i = 0; i < equipIds.length; i++) {
        equips[i] = [
            equipIds[i],
            $('#brand-' + equipIds[i]).val(),
            $('#year-' + equipIds[i]).val(),
            $('#num-' + equipIds[i]).val(),
            $('#equip-' + equipIds[i]).val()
        ];
    }
    var data = {
        app_access: app_access,
        token: userInfo.token,
        type: userInfo.type,
        cate: userInfo.cate,
        equips: equips
    };
    //console.log(equips); return;
    $.ajax({
        type: 'post',
        url: getDomain() + 'com-equip-set',
        data: data,
        success: function (res) {
            //console.log(res); return;
            if (res.code != 0) {
                getErrMsg(res.msg);
                return;
            }
            window.location.href = 'comYield.html';
        },
        error: function () {
            getErrMsg('操作失败！');
            return;
        }
    });
});

/**
 * ---------------------------------------------
 * 公司的工厂设备
 * ---------------------------------------------
 * */


/**
 * ---------------------------------------------
 * 公司产量产能
 * ---------------------------------------------
 * */

/**
 * 产量产能，获取
 * */
function getComYieldList() {
    var userInfo = cacheGet('userInfo'); //获取用户信息
    if (userInfo == 'undefined' || userInfo.token == 'undefined') {
        getErrMsg('没有登录！');
        return;
    }
    var data = {
        app_access: app_access,
        token: userInfo.token,
        type: userInfo.type,
        cate: userInfo.cate
    };
    $.ajax({
        type: 'post',
        url: getDomain() + 'com-yield-list',
        data: data,
        success: function (res) {
            //console.log(res); return;
            if (res.code != 0) {
                console.log(res.msg);
                return;
            }
            //console.log(res.data); return;
            var departs = res.data.departs;
            var dayOutPuts = res.data.dayOutPuts;
            var requirePros = res.data.requirePros;
            var requireDeparts = res.data.requireDeparts;
            var standards = res.data.standards;
            //部门人数
            var i, h = '', h4 = '';
            for (i = 0; i < departs.length; i++) {
                h += '<div class="goodsPanel">';
                h += '<div class="departName">' + departs[i].key + '</div>';
                h += '<div class="personNum">';
                h += '<input type="hidden" id="departKey-' + i + '" value="' + departs[i].key + '"/>';
                h += '<input type="text" class="regCodeCenter" placeholder="输入人数" id="departNum-' + i + '" value="';
                if (departs[i].num != 0) {
                    h += departs[i].num;
                }
                h += '"/>';
                h += '</div>';
                h += '</div>';
            }
            $('#departSpan').html(h);
            if (dayOutPuts[0] != 0) {
                $('#dayOutPutStart')[0].value = dayOutPuts[0];
            }
            if (dayOutPuts[1] != 0) {
                $('#dayOutPutEnd')[0].value = dayOutPuts[1];
            }
            //质量要求
            var i2, h2 = '';
            for (i2 = 0; i2 < requirePros.length; i2++) {
                h2 += '<div class="goodsPanel">';
                h2 += '<div class="goodsQuality">' + requirePros[i2].key + '</div>';
                h2 += '<div class="goodscheck">';
                h2 += '<label class="businessValue">';
                h2 += '<input type="radio" class="businessCheck" name="radio' + i2 + '" onclick="setRequirePro(' + i2 + ',1)"';
                if (requirePros[i2].val == 1) {
                    h2 += ' checked';
                }
                h2 += '/>';
                h2 += '一道';
                h2 += '</label> &nbsp;&nbsp;';
                h2 += '<label class="businessValue">';
                h2 += '<input type="radio" class="businessCheck" name="radio' + i2 + '" onclick="setRequirePro(' + i2 + ',2)"';
                if (requirePros[i2].val == 2) {
                    h2 += ' checked';
                }
                h2 += '/>';
                h2 += '二道';
                h2 += '</label> &nbsp;&nbsp;';




                h2 += '<label class="businessValue">';
                h2 += '<input type="radio" class="businessCheck" name="radio' + i2 + '" onclick="setRequirePro(' + i2 + ',3)"';
                if (requirePros[i2].val == 3) {
                    h2 += ' checked';
                }
                h2 += '/>';
                h2 += '三道';
                h2 += '</label> &nbsp;&nbsp;';


                h2 += '<label class="businessValue">';
                h2 += '<input type="radio" class="businessCheck" name="radio' + i2 + '" onclick="setRequirePro(' + i2 + ',4)"';
                if (requirePros[i2].val == 4) {
                    h2 += ' checked';
                }
                h2 += '/>';
                h2 += '四道';
                h2 += '</label> &nbsp;&nbsp;';


                h2 += '</div>';
                h2 += '</div>';
                h4 += '<input type="hidden" id="requireProKey-' + i2 + '" value="' + requirePros[i2].key + '"/>';
                h4 += '<input type="hidden" id="requireProVal-' + i2 + '" value="';
                if (!requirePros[i2].val || requirePros[i2].val == 0) {
                    h4 += 0;
                } else {
                    h4 += requirePros[i2].val;
                }
                h4 += '"/>';
            }
            $('#requireSpan').html(h2);
            //质量人数
            var i3, h3 = '';
            for (i3 = 0; i3 < requireDeparts.length; i3++) {
                h3 += '<div class="goodsPanel">';
                h3 += '<div class="departName">' + requireDeparts[i3].key + '</div>';
                h3 += '<div class="personNum">';
                h3 += '<input type="text" class="regCodeCenter" placeholder="输入人数" id="requireDepartNum-' + i3 + '" value="';
                if (requireDeparts[i3].num != 0) {
                    h3 += requireDeparts[i3].num;
                }
                h3 += '"/>';
                h3 += '</div>';
                h3 += '</div>';
                h4 += '<input type="hidden" id="requireDepartKey-' + i3 + '" value="' + requireDeparts[i3].key + '"/>';
            }
            $('#requireDepartSpan').html(h3);
            //标准
            var standardArr = [
                '《工艺单》、样品',
                '摊平用尺量用目视用手摸',
                '质检：每件产品全检',
                '总检：抽查品质、尺寸',
                '巡检：对在线生产产品巡查'
            ];
            var i4, h5 = '';
            for (i4 = 0; i4 < standards.length; i4++) {
                h5 += '<div class="checkStandardDiv"><label>';
                h5 += '<input type="checkbox" onclick="setStandard(' + i4 + ')"';
                if (standards[i4] != 0) {
                    h5 += ' checked';
                }
                h5 += '/>&nbsp;';
                h5 += '<span class="standardContent">' + standardArr[i4] + '</span>';
                h5 += '</label></div>';
                h4 += '<input type="hidden" id="standard-' + i4 + '" value="';
                if (standards[i4] != 0) {
                    h4 += 1;
                } else {
                    h4 += 0;
                }
                h4 += '"/>';
            }
            h4 += '<input type="hidden" id="departCount" value="' + departs.length + '"/>';
            h4 += '<input type="hidden" id="requireProCount" value="' + requirePros.length + '"/>';
            h4 += '<input type="hidden" id="requireDepartCount" value="' + requireDeparts.length + '"/>';
            $('#standardlist').html(h5);
            $('#standardSpan').html(h4);
        },
        error: function () {
            console.log('操作失败！');
            return;
        }
    });
}

/**
 * 产量产能，质量要求产品，设置
 * */
function setRequirePro(v, t) {
    $('#requireProVal-' + v)[0].value = t;
}

/**
 * 产量产能，质量标准，设置
 * */
function setStandard(v) {
    var standard = $('#standard-' + v).val();
    if (standard != 0) {
        $('#standard-' + v)[0].value = 0;
    } else {
        $('#standard-' + v)[0].value = 1;
    }
}

/**
 * 产量产能，设置提交
 * */
$('#comYieldNext').on('click', function () {
    var userInfo = cacheGet('userInfo'); //获取用户信息
    if (userInfo == 'undefined' || userInfo.token == 'undefined') {
        getErrMsg('没有登录！');
        return;
    }
    var departCount = $('#departCount').val();
    var requireProCount = $('#requireProCount').val();
    var requireDepartCount = $('#requireDepartCount').val();
    var departs = new Array(),
        requirePros = new Array(),
        requireDeparts = new Array(),
        standards = new Array();
    var i, i2, i3, num, num2;
    //部门人数
    for (i = 0; i < departCount; i++) {
        num = $('#departNum-' + i).val();
        if (num == '') {
            num = 0;
        }
        departs[i] = {
            key: $('#departKey-' + i).val(),
            num: num
        };
    }
    //日产量
    var dayOutPutStart = $('#dayOutPutStart').val();
    var dayOutPutEnd = $('#dayOutPutEnd').val();
    if (dayOutPutStart == '') {
        dayOutPutStart = 0;
    }
    if (dayOutPutEnd == '') {
        dayOutPutEnd = 0;
    }
    var dayOutPuts = [
        dayOutPutStart, dayOutPutEnd
    ];
    //质量要求
    for (i2 = 0; i2 < requireProCount; i2++) {
        var val = $('#requireProVal-' + i2).val();
        if (val == '') {
            val = 0;
        }
        requirePros[i2] = {
            key: $('#requireProKey-' + i2).val(), val: val
        };
    }
    //质量人数
    for (i3 = 0; i3 < requireDepartCount; i3++) {
        num = $('#requireDepartNum-' + i3).val();
        if (num == '') {
            num = 0;
        }
        requireDeparts[i3] = {
            key: $('#requireDepartKey-' + i3).val(), num: num
        };
    }
    //标准
    standards[0] = $('#standard-0').val();
    standards[1] = $('#standard-1').val();
    standards[2] = $('#standard-2').val();
    standards[3] = $('#standard-3').val();
    standards[4] = $('#standard-4').val();
    var yields = {
        departs: departs,
        dayOutPuts: dayOutPuts,
        requirePros: requirePros,
        requireDeparts: requireDeparts,
        standards: standards
    };
    //console.log(yields); return;
    var data = {
        app_access: app_access,
        token: userInfo.token,
        type: userInfo.type,
        cate: userInfo.cate,
        yields: yields
    };
    $.ajax({
        type: 'post',
        url: getDomain() + 'com-yield-set',
        data: data,
        success: function (res) {
            //console.log(res); return;
            if (res.code != 0) {
                getErrMsg(res.msg);
                return;
            }
            window.location.href = 'comEnv.html';
        },
        error: function () {
            getErrMsg('操作失败！');
            return;
        }
    });
});

/**
 * ---------------------------------------------
 * 公司产量产能
 * ---------------------------------------------
 * */


/**
 * ---------------------------------------------
 * 公司环境
 * ---------------------------------------------
 * */

/**
 * 环境，获取
 * */
function getComEnvFiles() {
    var userInfo = cacheGet('userInfo'); //获取用户信息
    if (userInfo == null || userInfo.token == 'undefined') {
        getErrMsg('没有登录！');
        return;
    }
    var data = {
        app_access: app_access,
        token: userInfo.token,
        type: userInfo.type,
        cate: userInfo.cate
    };
    $.ajax({
        type: 'post',
        url: getDomain() + 'com-env-file',
        data: data,
        success: function (res) {
            //console.log(res); return;
            if (res.code != 0) {
                console.log(res);
                return;
            }
            //console.log(res.data); return;
            var i, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12,
                i13, i14, i15, i16, i17, i18, i19, i20, i21, i22,
                i23, i24,
                managers, manager2s, directors, handles, finances, officers,
                sales, expands, designs, buyers, sellers, produces, qcs,
                storages, transports, outs, meetings, halls, stages, talks,
                cooks, wcs, teas, dorms,
                h = '', h2 = '', h3 = '', h4 = '', h5 = '', h6 = '',
                h7 = '', h8 = '', h9 = '', h10 = '', h11 = '', h12 = '',
                h13 = '', h14 = '', h15 = '', h16 = '', h17 = '', h18 = '',
                h19 = '', h20 = '', h21 = '', h22 = '', h23 = '', h24 = '',
                h25 = '', h26 = '';
            managers = res.data.managers;
            if (managers.length > 0) {
                for (i = 0; i < managers.length; i++) {
                    h += '<img src="' + managers[i] + '" width="100%"/>';
                }
                $('#managerShow').html(h).show();
            }
            manager2s = res.data.manager2s;
            if (manager2s.length > 0) {
                for (i2 = 0; i2 < manager2s.length; i2++) {
                    h2 += '<img src="' + manager2s[i2] + '" width="100%"/>';
                }
                $('#manager2Show').html(h2).show();
            }
            directors = res.data.directors;
            if (directors.length > 0) {
                for (i3 = 0; i3 < directors.length; i3++) {
                    h3 += '<img src="' + directors[i3] + '" width="100%"/>';
                }
                $('#directorShow').html(h3).show();
            }
            handles = res.data.handles;
            if (handles.length > 0) {
                for (i4 = 0; i4 < handles.length; i4++) {
                    h4 += '<img src="' + handles[i4] + '" width="100%"/>';
                }
                $('#handleShow').html(h4).show();
            }
            finances = res.data.finances;
            if (finances.length > 0) {
                for (i5 = 0; i5 < finances.length; i5++) {
                    h5 += '<img src="' + finances[i5] + '" width="100%"/>';
                }
                $('#financeShow').html(h5).show();
            }
            officers = res.data.officers;
            if (officers.length > 0) {
                for (i6 = 0; i6 < officers.length; i6++) {
                    h6 += '<img src="' + officers[i6] + '" width="100%"/>';
                }
                $('#officerShow').html(h6).show();
            }
            sales = res.data.sales;
            if (sales.length > 0) {
                for (i7 = 0; i7 < sales.length; i7++) {
                    h7 += '<img src="' + sales[i7] + '" width="100%"/>';
                }
                $('#saleShow').html(h7).show();
            }
            expands = res.data.expands;
            if (expands.length > 0) {
                for (i8 = 0; i8 < expands.length; i8++) {
                    h8 += '<img src="' + expands[i8] + '" width="100%"/>';
                }
                $('#expandShow').html(h8).show();
            }
            designs = res.data.designs;
            if (designs.length > 0) {
                for (i9 = 0; i9 < designs.length; i9++) {
                    h9 += '<img src="' + designs[i9] + '" width="100%"/>';
                }
                $('#designShow').html(h9).show();
            }
            buyers = res.data.buyers;
            if (buyers.length > 0) {
                for (i10 = 0; i10 < buyers.length; i10++) {
                    h10 += '<img src="' + buyers[i10] + '" width="100%"/>';
                }
                $('#buyerShow').html(h10).show();
            }
            sellers = res.data.sellers;
            if (sellers.length > 0) {
                for (i11 = 0; i11 < sellers.length; i11++) {
                    h11 += '<img src="' + sellers[i11] + '" width="100%"/>';
                }
                $('#sellerShow').html(h11).show();
            }
            produces = res.data.produces;
            if (produces.length > 0) {
                for (i12 = 0; i12 < produces.length; i12++) {
                    h12 += '<img src="' + produces[i12] + '" width="100%"/>';
                }
                $('#produceShow').html(h12).show();
            }
            qcs = res.data.qcs;
            if (qcs.length > 0) {
                for (i13 = 0; i13 < qcs.length; i13++) {
                    h13 += '<img src="' + qcs[i13] + '" width="100%"/>';
                }
                $('#qcShow').html(h13).show();
            }
            storages = res.data.storages;
            if (storages.length > 0) {
                for (i14 = 0; i14 < storages.length; i14++) {
                    h14 += '<img src="' + storages[i14] + '" width="100%"/>';
                }
                $('#storageShow').html(h14).show();
            }
            transports = res.data.transports;
            if (transports.length > 0) {
                for (i15 = 0; i15 < transports.length; i15++) {
                    h15 += '<img src="' + transports[i15] + '" width="100%"/>';
                }
                $('#transportShow').html(h15).show();
            }
            outs = res.data.outs;
            if (outs.length > 0) {
                for (i16 = 0; i16 < outs.length; i16++) {
                    h16 += '<img src="' + outs[i16] + '" width="100%"/>';
                }
                $('#outShow').html(h16).show();
            }
            meetings = res.data.meetings;
            if (meetings.length > 0) {
                for (i17 = 0; i17 < meetings.length; i17++) {
                    h17 += '<img src="' + meetings[i17] + '" width="100%"/>';
                }
                $('#meetingShow').html(h17).show();
            }
            halls = res.data.halls;
            if (halls.length > 0) {
                for (i18 = 0; i18 < halls.length; i18++) {
                    h18 += '<img src="' + halls[i18] + '" width="100%"/>';
                }
                $('#hallShow').html(h18).show();
            }
            stages = res.data.stages;
            if (stages.length > 0) {
                for (i19 = 0; i19 < stages.length; i19++) {
                    h19 += '<img src="' + stages[i19] + '" width="100%"/>';
                }
                $('#stagelShow').html(h19).show();
            }
            talks = res.data.talks;
            if (talks.length > 0) {
                for (i20 = 0; i20 < talks.length; i20++) {
                    h20 += '<img src="' + talks[i20] + '" width="100%"/>';
                }
                $('#talkShow').html(h20).show();
            }
            cooks = res.data.cooks;
            if (cooks.length > 0) {
                for (i21 = 0; i21 < cooks.length; i21++) {
                    h21 += '<img src="' + cooks[i21] + '" width="100%"/>';
                }
                $('#cookShow').html(h21).show();
            }
            wcs = res.data.wcs;
            if (wcs.length > 0) {
                for (i22 = 0; i22 < wcs.length; i22++) {
                    h22 += '<img src="' + wcs[i22] + '" width="100%"/>';
                }
                $('#wcShow').html(h22).show();
            }
            teas = res.data.teas;
            if (teas.length > 0) {
                for (i23 = 0; i23 < teas.length; i23++) {
                    h23 += '<img src="' + teas[i23] + '" width="100%"/>';
                }
                $('#teaShow').html(h23).show();
            }
            dorms = res.data.dorms;
            if (dorms.length > 0) {
                for (i24 = 0; i24 < dorms.length; i24++) {
                    h24 += '<img src="' + dorms[i24] + '" width="100%"/>';
                }
                $('#dormShow').html(h24).show();
            }
        },
        error: function () {
            console.log('操作失败！');
            return;
        }
    });
}

/**
 * 环境，设置
 * */
function setFormComEnv(type) {
    var userInfo = cacheGet('userInfo'); //获取用户信息
    if (userInfo == null || userInfo.token == 'undefined') {
        getErrMsg('没有登录！');
        return;
    }
    $('form').attr('action', getDomain() + 'com-env-upload');
    var h = '';
    h += '<input type="hidden" name="app_access" value="' + app_access + '">';
    h += '<input type="hidden" name="token" value="' + userInfo.token + '">';
    h += '<input type="hidden" name="type" value="' + userInfo.type + '">';
    h += '<input type="hidden" name="cate" value="' + userInfo.cate + '">';
    h += '<input type="hidden" name="viewJump" value="/h5/login/comEnv.html">';
    $('.param').html(h);
    $('#submit-' + type).show();
}

/**
 * ---------------------------------------------
 * 公司环境
 * ---------------------------------------------
 * */


/**
 * ---------------------------------------------
 * 公司原料面料
 * ---------------------------------------------
 * */

/**
 * 获取
 * */
function getComFabricList() {
    var userInfo = cacheGet('userInfo'); //获取用户信息
    if (userInfo == null || userInfo.token == 'undefined') {
        getErrMsg('没有登录！', '');
        return;
    }
    var data = {
        app_access: app_access,
        token: userInfo.token,
        type: userInfo.type,
        cate: userInfo.cate
    };
    $.ajax({
        type: 'post',
        url: getDomain() + 'com-fabric-list',
        data: data,
        success: function (res) {
            //console.log(res); return;
            if (res.code != 0) {
                console.log(res);
                return;
            }
            //console.log(res.data); return;
            var data = res.data;
            var i, i2, num = 0, h = '';
            for (i = 0; i < data.length; i++) {
                h += '<table class="table" cellspacing="0">';
                h += '<tr>';
                h += '<td><b>' + data[i].type.typeName + '</b></td>';
                h += '<td><b>费用（元）</b></td>';
                h += '</tr>';
                var subs = data[i].subs;
                if (subs) {
                    for (i2 = 0; i2 < subs.length; i2++) {
                        h += '<tr>';
                        h += '<td>' + subs[i2].name + '</td>';
                        h += '<td>';
                        h += '<input type="text" id="cost_' + subs[i2].id + '" value="' + subs[i2].cost + '"/>';
                        h += '<input type="hidden" id="costName_' + num + '" value="' + subs[i2].name + '"/>';
                        h += '<input type="hidden" id="costNum_' + num + '" value="' + subs[i2].id + '"/>';
                        h += '</td>';
                        h += '</tr>';
                        num++;
                    }
                }
                h += '<input type="hidden" id="costNum" value="' + num + '">';
                h += '</table>';
            }
            $('#tablelist').html(h);
        },
        error: function () {
            console.log('操作失败！');
            return;
        }
    });
}

///**
// * 公司原料面料
// * */
//function setComFabric(){
//    var userInfo = cacheGet('userInfo'); //获取用户信息
//    if (userInfo==null || userInfo.token=='undefined') {
//        getErrMsg('没有登录！',''); return;
//    }
//    var costNum = $('#costNum').val();
//    var i, costId, costArr = new Array();
//    for (i=0;i<costNum-1;i++) {
//        costId = $('#costNum_'+i).val();
//        costArr[i] = {
//            id:costId,
//            name:$('#costName_'+costId).val(),
//            cost:$('#cost_'+costId).val()
//        };
//    }
//    var data = {
//        app_access:app_access,
//        token:userInfo.token,
//        type:userInfo.type,
//        cate:userInfo.cate,
//        costs:costArr
//    };
//    $.ajax({
//        type:'post',
//        url:getDomain() + 'fac-fabric-set',
//        data:data,
//        success:function(res){
////                console.log(res); return;
//            if (res.code!=0) {
//                console.log(res); return;
//            }
//            //console.log(res.data); return;
//            window.location.href = '/h5/login/facList.html';
//        },
//        error:function(){
//            console.log('操作失败！'); return;
//        }
//    });
//}

/**
 * ---------------------------------------------
 * 公司原料面料
 * ---------------------------------------------
 * */


/**
 * 地址前缀
 * */
function getDomain() {
    return '/api/member/company/';
}


///**
// * -------------------------
// * 本地缓存
// * -------------------------
// * */
//
///**
// * 本地缓存，获取
// * */
//function cacheGet(key){
//    //return localStorage.getItem(key);
//    return JSON.parse(localStorage.getItem(key));
//}
//
///**
// * 本地缓存，新增
// * */
//function cacheSet(key,val){
//    //var cache = cacheGet(key);
//    //if (cache!='undefined') { getErrMsg('已存在！'); }
//    //localStorage.setItem(key,val);
//    //为防止没有设置值获取后出现object类型 转化出错,提前进行设置空字符串
//    localStorage.setItem(key, "");
//    localStorage.setItem(key, JSON.stringify(val));
//}
//
///**
// * 本地缓存，删除
// * */
//function cacheDel(key){
//    localStorage.remove(key);
//}
//
///**
// * 本地缓存，删除
// * */
//function cacheClear(){
//    localStorage.clear();
//}


/**
 * 错误提示框
 * */
function getErrMsg(msg) {
    var h = '';
    h += '<span>' + msg + '</span>';
    h += '<script>setTimeout("setErrClose()",1000*3); function setErrClose(){ $("#errMsg").html("").hide(); }</script>';
    $('#errMsg').html(h).show();
}

// 地区选择

$('#comCity').on('click', function () {
    return;
    var locationObj = {
        app_access: app_access,
        tag: '#IstepThreeNoFactoryCompanyInfo', // 文档元素
        clickTag: '#comCity', // 设置地区元素
        city: true, // 是否启用城市选择
        region: false // 是否启用地区选择
    }
    provinceAJAX(locationObj)
})